package com.itheima;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.function.Consumer;


public class ArrayListDemo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("zhangsan11");
        list.add(0, "lisi");
        String s = list.get(1);
        System.out.println(s);
        list.set(0, "wangwu");
        list.remove(1);
        list.add("zhangsan");
        list.add("lisi");
        list.add("wangwu");
        list.add("zhaoliu");
        list.add("zhangsan");
        list.add("zhangsan");
        System.out.println(list);
        System.out.println("----------------------集合的遍历方法-------------------------");
        for (int i = 0; i < list.size(); i++) {
            String obj = list.get(i);
            System.out.println(obj);
        }
        System.out.println("----------------------集合的遍历方法2-------------------------");
        for (String obj : list) {
            System.out.println(obj);
        }
        System.out.println("----------------------集合的遍历方法3-------------------------");
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);
        }
        System.out.println("----------------------集合的遍历方法4-------------------------");
        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        list.forEach( name -> System.out.println(name));
        list.forEach(System.out::println);

    }

}
